package com.domain;

import com.itextpdf.text.pdf.PdfStamper;
import com.itextpdf.text.pdf.PdfWriter;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.nio.charset.StandardCharsets;

/**
 * 水印/密码
 *  参考文档： https://blog.csdn.net/qq_35651352/article/details/124140043
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PdfUser {

    /**
     * 用户密码
     */
    private String userPassword = "55555";

    /**
     * 管理员密码
     */
    private String adminPassword = "666666";

    /**
     * 设置pdf密码
     *
     * @param stamper
     * @param userPassword
     * @param adminPassword
     */
    public void lock(PdfStamper stamper, String userPassword, String adminPassword) {
        try {
            stamper.setEncryption(userPassword.getBytes(StandardCharsets.UTF_8),
                    adminPassword.getBytes(StandardCharsets.UTF_8),
                    PdfWriter.ALLOW_PRINTING | PdfWriter.ALLOW_COPY, PdfWriter.ENCRYPTION_AES_128);
        }catch (Exception e) {
            e.printStackTrace();
        }
    }

}
